def triplet_with_smaller_sum(arr, target):
  count = 0
  # TODO: Write your code here
  arr.sort()
  for i in range(len(arr)-2):
    left = i+1
    right = len(arr)-1
    target_temp = target - arr[i]
    while(left<right):
      if((arr[left]+arr[right]) < target_temp):
        count+=right-left
        left+=1
      else:
        right-=1

  return count


def main():
  print(triplet_with_smaller_sum([-1, 0, 2, 3], 3))
  print(triplet_with_smaller_sum([-1, 4, 2, 1, 3], 5))


main()